#include <math.h>
#include <fstream>
#include <iostream>
#include <memory>
#include <dlfcn.h>
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image.h"
#include "stb_image_write.h"

#include <MNN/ImageProcess.hpp>
#include <MNN/Interpreter.hpp>
#include "PoseNames.hpp"

#define MNN_OPEN_TIME_TRACE
#include <MNN/AutoTime.hpp>
using namespace MNN;

int main(int argc, char* argv[]) {
    if (argc < 2) {
        std::cout << "Usage: ./multiPose.out model.mnn input.jpg pose.jpg" << std::endl;
    }

    const auto poseModel           = argv[1];
    auto mnnNet = std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(poseModel));
    MNN::ScheduleConfig netConfig;
    netConfig.numThread = 4;
    
    auto session        = mnnNet->createSession(netConfig);
     
    auto inputTensor = mnnNet->getSessionInput(session, NULL);
    auto nchwTensor = new Tensor(inputTensor, Tensor::CAFFE);
    nchwTensor->host<float>()[0] = -0.882353;
    nchwTensor->host<float>()[1] = -0.145729;
    nchwTensor->host<float>()[2] = 0.0819672;
    nchwTensor->host<float>()[3] = -0.414141;
    nchwTensor->host<float>()[4] = 0;
    nchwTensor->host<float>()[5] = -0.207153;
    nchwTensor->host<float>()[6] = -0.766866;
    nchwTensor->host<float>()[7] = -0.666667;

    inputTensor->copyFromHostTensor(nchwTensor);
    delete nchwTensor;

    {
        AUTOTIME;
        mnnNet->runSession(session);
    }
    
    auto outputTensor = mnnNet->getSessionOutput(session, NULL);
    auto score = outputTensor->host<float>()[0];
    
    std::cout << score << std::endl;
    
    return 0;
}
